package com.djx.comm;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.Data;

import java.util.List;

/**
 * 分页组件
 * @author dingjunxiong
 */
@Data
public class Pagination<T> {
    /**
     * 页数
     */
    private Integer pageNum;
    /**
     * 条数
     */
    private Integer pageSize;
    private PageInfo<T> page;
    /**
     * 是否分页，默认分页
     */
    private Boolean ifPaging;

    public void setResult(List<T> list) {
        page = new PageInfo(list);
    }

    public void startPage() {
        if (this.pageNum == null || this.pageSize == null) {
            this.pageNum = 1;
            this.pageSize = 10;
        }
        if (this.ifPaging != null && !this.ifPaging) {
            //不分页
            PageHelper.startPage(this.pageNum, 0, false, false, true);
        } else {
            PageHelper.startPage(this.pageNum, this.pageSize);
        }
    }

}

